using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletPoolM : MonoBehaviour
{
    public GameObject bullet_player;
    Queue<GameObject> bulletpool;
    int bulletpoolnum = 30;
    // Start is called before the first frame update
    void Start()
    {
        bulletpool = new Queue<GameObject>();
        GameObject bullet = null;
        for(int i =0;i< bulletpoolnum; i++)
        {
            bullet = Instantiate(bullet_player);
            bullet.SetActive(false);
            bulletpool.Enqueue(bullet);
        }
    }

    private void Awake()
    {
    }
    public GameObject getbullet()
    {
        if(bulletpool.Count>0)
        {
            GameObject bullet = bulletpool.Dequeue();
            bullet.SetActive(true);
            return bullet;
        }
        else
        {
            return Instantiate(bullet_player);
        }
    }

    public void recoverBullet(GameObject bullet)
    {
        bullet.SetActive(false);
        bulletpool.Enqueue(bullet);
    }
}
